package com.richard.study.test.proxy;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

/**
 * Created with IntelliJ IDEA.
 *
 * @author YaoXiansheng
 * @date 2019/3/20 22:19
 * Description:
 */
public class JavaDynamicProxy implements InvocationHandler {

    private Object target;

    public Object bindTarge(Object target) {
        this.target = target;
        return Proxy.newProxyInstance(target.getClass().getClassLoader(), target.getClass().getInterfaces(), this);
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        System.out.println("---Before proxy---");
        Object result = method.invoke(target, args);
        System.out.println("---After proxy---");
        return result;
    }
}
